package com.xuecheng.media.controller;

import com.xuecheng.api.media.model.MediaApi;
import com.xuecheng.api.media.model.aliyun.dto.MediaDTO;
import com.xuecheng.api.media.model.aliyun.qo.QueryMediaModel;
import com.xuecheng.api.media.model.aliyun.vo.MediaAuditVO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.media.common.utils.UAASecurityUtil;
import com.xuecheng.media.convert.MediaConvert;
import com.xuecheng.media.service.MediaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
public class MediaAuditController implements MediaApi {

    // 运营平台标识--可以查询所有教学机构的数据
    public static final Long OPERATION_FLAG = -99887799L;

    @Autowired
    private MediaService mediaService;

    /**
     * 带条件分页查询
     *
     * @param params          封装分页数据
     * @param queryMediaModel 前端传入课程基础信息 Qo
     * @return PageVO 分页结果封装
     */
    @PostMapping("m/media/list")
    public PageVO queryMediaList(PageRequestParams params,
                                 @RequestBody QueryMediaModel queryMediaModel) {

        //调用service分页查询,PageVO接收
        PageVO<MediaDTO> pageVO = mediaService.queryMediaList(params, queryMediaModel, OPERATION_FLAG);
        return pageVO;
    }

    /**
     * 课程信息审核实现-运营
     *
     * @param mediaAuditVO 课程审核时的VO对象
     */
    @PutMapping("m/media/audit")
    public void approve(@RequestBody MediaAuditVO mediaAuditVO) {

        MediaDTO mediaDTO = MediaConvert.INSTANCE.auditvo2dto(mediaAuditVO);
        //审核
        mediaService.approve(mediaDTO);
    }


    @GetMapping("m/media/preview/{mediaId}")
    public String previewMedia(@PathVariable Long mediaId) {

//        Long companyId = UAASecurityUtil.getCompanyId();

        String vodUrl = mediaService.getVODUrl(mediaId, OPERATION_FLAG);

        return vodUrl;
    }


    @GetMapping("l/media/{mediaId}")
    public RestResponse<MediaDTO> getMediaById(@PathVariable Long mediaId) {

        RestResponse<MediaDTO> response = mediaService.getById4Service(mediaId);

        return response;
    }
}
